package com.luyuan.gallery.converter;

import com.luyuan.gallery.vo.CommentVO;
import com.luyuan.gallery.domain.ExhiComment;
import com.luyuan.common.utils.bean.BeanUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * 评论VO转换器
 * 
 * @author luyuan
 * @date 2025-11-07
 */
public class CommentVOConverter {
    /**
     * 将实体类转换为VO
     * 
     * @param exhiComment 评论实体
     * @return 评论VO
     */
    public static CommentVO toVO(ExhiComment exhiComment) {
        if (exhiComment == null) {
            return null;
        }

        CommentVO commentVO = new CommentVO();
        BeanUtils.copyBeanProp(commentVO, exhiComment);
        return commentVO;
    }

    /**
     * 将VO转换为实体类
     * 
     * @param commentVO 评论VO
     * @return 评论实体
     */
    public static ExhiComment toEntity(CommentVO commentVO) {
        if (commentVO == null) {
            return null;
        }

        ExhiComment exhiComment = new ExhiComment();
        BeanUtils.copyBeanProp(exhiComment, commentVO);
        return exhiComment;
    }

    /**
     * 将实体类列表转换为VO列表
     * 
     * @param exhiComments 评论实体列表
     * @return 评论VO列表
     */
    public static List<CommentVO> toVOList(List<ExhiComment> exhiComments) {
        if (exhiComments == null) {
            return null;
        }

        List<CommentVO> commentVOs = new ArrayList<>();
        for (ExhiComment exhiComment : exhiComments) {
            commentVOs.add(toVO(exhiComment));
        }
        return commentVOs;
    }

    /**
     * 将VO列表转换为实体类列表
     * 
     * @param commentVOs 评论VO列表
     * @return 评论实体列表
     */
    public static List<ExhiComment> toEntityList(List<CommentVO> commentVOs) {
        if (commentVOs == null) {
            return null;
        }

        List<ExhiComment> exhiComments = new ArrayList<>();
        for (CommentVO commentVO : commentVOs) {
            exhiComments.add(toEntity(commentVO));
        }
        return exhiComments;
    }
}